from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-19 14:12:47.421700
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 19, Aug, 2021
Time: 14:12:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6949
Nobs: 388.000 HQIC: -46.2494
Log likelihood: 4178.13 FPE: 5.70110e-21
AIC: -46.6137 Det(Omega_mle): 4.53416e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437725 0.095961 4.561 0.000
L1.Burgenland 0.102641 0.049638 2.068 0.039
L1.Kärnten -0.115900 0.024567 -4.718 0.000
L1.Niederösterreich 0.166324 0.107090 1.553 0.120
L1.Oberösterreich 0.121041 0.105980 1.142 0.253
L1.Salzburg 0.289005 0.052033 5.554 0.000
L1.Steiermark 0.019840 0.068881 0.288 0.773
L1.Tirol 0.114881 0.054313 2.115 0.034
L1.Vorarlberg -0.115289 0.049081 -2.349 0.019
L1.Wien -0.013604 0.094825 -0.143 0.886
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.006914 0.223946 0.031 0.975
L1.Burgenland -0.052323 0.115842 -0.452 0.652
L1.Kärnten 0.034706 0.057332 0.605 0.545
L1.Niederösterreich -0.260696 0.249919 -1.043 0.297
L1.Oberösterreich 0.554874 0.247329 2.243 0.025
L1.Salzburg 0.314930 0.121430 2.594 0.010
L1.Steiermark 0.111048 0.160750 0.691 0.490
L1.Tirol 0.304055 0.126752 2.399 0.016
L1.Vorarlberg -0.011266 0.114543 -0.098 0.922
L1.Wien 0.010090 0.221295 0.046 0.964
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.251393 0.048705 5.162 0.000
L1.Burgenland 0.094118 0.025194 3.736 0.000
L1.Kärnten -0.003028 0.012469 -0.243 0.808
L1.Niederösterreich 0.232876 0.054353 4.284 0.000
L1.Oberösterreich 0.156198 0.053790 2.904 0.004
L1.Salzburg 0.036429 0.026409 1.379 0.168
L1.Steiermark 0.011896 0.034961 0.340 0.734
L1.Tirol 0.071303 0.027566 2.587 0.010
L1.Vorarlberg 0.056575 0.024911 2.271 0.023
L1.Wien 0.093271 0.048128 1.938 0.053
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187531 0.047547 3.944 0.000
L1.Burgenland 0.045695 0.024595 1.858 0.063
L1.Kärnten -0.006833 0.012172 -0.561 0.575
L1.Niederösterreich 0.126758 0.053061 2.389 0.017
L1.Oberösterreich 0.312748 0.052511 5.956 0.000
L1.Salzburg 0.102191 0.025781 3.964 0.000
L1.Steiermark 0.139700 0.034129 4.093 0.000
L1.Tirol 0.074668 0.026911 2.775 0.006
L1.Vorarlberg 0.055500 0.024319 2.282 0.022
L1.Wien -0.038730 0.046984 -0.824 0.410
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204654 0.094725 2.160 0.031
L1.Burgenland -0.063122 0.048999 -1.288 0.198
L1.Kärnten -0.036180 0.024250 -1.492 0.136
L1.Niederösterreich 0.084385 0.105711 0.798 0.425
L1.Oberösterreich 0.199012 0.104616 1.902 0.057
L1.Salzburg 0.264528 0.051363 5.150 0.000
L1.Steiermark 0.075543 0.067995 1.111 0.267
L1.Tirol 0.121631 0.053614 2.269 0.023
L1.Vorarlberg 0.114966 0.048450 2.373 0.018
L1.Wien 0.038936 0.093604 0.416 0.677
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025569 0.074134 0.345 0.730
L1.Burgenland 0.026572 0.038348 0.693 0.488
L1.Kärnten 0.050671 0.018979 2.670 0.008
L1.Niederösterreich 0.197930 0.082732 2.392 0.017
L1.Oberösterreich 0.346880 0.081874 4.237 0.000
L1.Salzburg 0.046866 0.040198 1.166 0.244
L1.Steiermark -0.000625 0.053214 -0.012 0.991
L1.Tirol 0.112984 0.041959 2.693 0.007
L1.Vorarlberg 0.061635 0.037918 1.626 0.104
L1.Wien 0.133033 0.073256 1.816 0.069
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185028 0.090407 2.047 0.041
L1.Burgenland 0.016679 0.046765 0.357 0.721
L1.Kärnten -0.057230 0.023145 -2.473 0.013
L1.Niederösterreich -0.120323 0.100892 -1.193 0.233
L1.Oberösterreich 0.195259 0.099846 1.956 0.051
L1.Salzburg 0.030848 0.049021 0.629 0.529
L1.Steiermark 0.299066 0.064895 4.608 0.000
L1.Tirol 0.493226 0.051169 9.639 0.000
L1.Vorarlberg 0.065557 0.046241 1.418 0.156
L1.Wien -0.105132 0.089337 -1.177 0.239
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163290 0.098405 1.659 0.097
L1.Burgenland -0.006467 0.050903 -0.127 0.899
L1.Kärnten 0.062974 0.025192 2.500 0.012
L1.Niederösterreich 0.195305 0.109818 1.778 0.075
L1.Oberösterreich -0.121089 0.108680 -1.114 0.265
L1.Salzburg 0.244810 0.053358 4.588 0.000
L1.Steiermark 0.153501 0.070636 2.173 0.030
L1.Tirol 0.050747 0.055696 0.911 0.362
L1.Vorarlberg 0.120937 0.050332 2.403 0.016
L1.Wien 0.139186 0.097240 1.431 0.152
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.491574 0.053396 9.206 0.000
L1.Burgenland -0.012502 0.027621 -0.453 0.651
L1.Kärnten -0.009348 0.013670 -0.684 0.494
L1.Niederösterreich 0.201290 0.059589 3.378 0.001
L1.Oberösterreich 0.258047 0.058971 4.376 0.000
L1.Salzburg 0.021115 0.028953 0.729 0.466
L1.Steiermark -0.022182 0.038328 -0.579 0.563
L1.Tirol 0.067323 0.030222 2.228 0.026
L1.Vorarlberg 0.057917 0.027311 2.121 0.034
L1.Wien -0.050756 0.052764 -0.962 0.336
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018243 0.078634 0.137214 0.129190 0.043870 0.071261 0.002044 0.178947
Kärnten 0.018243 1.000000 -0.056242 0.128285 0.044976 0.067961 0.457408 -0.093783 0.097410
Niederösterreich 0.078634 -0.056242 1.000000 0.287989 0.092899 0.275971 0.016531 0.149892 0.254033
Oberösterreich 0.137214 0.128285 0.287989 1.000000 0.175579 0.293053 0.162878 0.119623 0.135430
Salzburg 0.129190 0.044976 0.092899 0.175579 1.000000 0.130313 0.051612 0.109756 0.051170
Steiermark 0.043870 0.067961 0.275971 0.293053 0.130313 1.000000 0.127739 0.087944 -0.021558
Tirol 0.071261 0.457408 0.016531 0.162878 0.051612 0.127739 1.000000 0.040079 0.118496
Vorarlberg 0.002044 -0.093783 0.149892 0.119623 0.109756 0.087944 0.040079 1.000000 -0.048532
Wien 0.178947 0.097410 0.254033 0.135430 0.051170 -0.021558 0.118496 -0.048532 1.000000